<% layout('/layouts/default.html', {title: '用户管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header with-border">
            <div class="box-title">
                <i class="fa icon-people"></i> ${text(empUser.isNewRecord ? '查看用户' : op == 'auth' ? '用户分配角色' : '查看用户')}
                <% if (hasPermi('sys:empUser:edit')){ %>
                <button type="button" class="btn btn-primary" id="editView">${text('编辑单据')}</button>
                <% } %>
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            </div>
        </div>
        <#form:form id="inputForm" model="${empUser}" action="${ctx}/sys/empUser/save" method="post" class="form-horizontal">
        <#form:hidden name="op" value="${op}"/>
        <#form:hidden name="userType" value="employee"/>
        <div class="box-body">
            <% if(op=='auth'){ %><br/><% } %>
            <% if(op == 'add' || op == 'edit') { %>
            <div class="form-unit">${text('基本信息')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('员工编号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="userCode" id="userCode" placeholder="自动生成" maxlength="64" readonly="true" class="form-control" disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('姓名')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="userName" maxlength="32" readonly="${op=='auth'}" class="form-control" disabled="true"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required">*</span> ${text('登录账号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:hidden name="oldLoginCode" value="${empUser.loginCode}"/>
                            <#form:input path="loginCode" minlength="4" maxlength="20" readonly="${op=='auth'}"
                            class="form-control required userName"
                            remote="${ctx}/sys/user/checkLoginCode?oldLoginCode=${empUser.loginCode}"
                            data-msg-remote="${text('登录账号已存在')}" disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('工号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="employee.empNo" maxlength="32" class="form-control userName"
                            remote="${ctx}/sys/empUser/checkEmpNo?oldEmpNo=${empUser.employee.empNo}"
                            data-msg-remote="${text('员工工号已存在')}" disabled="true"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('归属部门')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:treeselect id="office" title="${text('部门选择')}"
                            path="employee.office.officeCode" labelPath="employee.office.officeName"
                            url="${ctx}/sys/office/treeData?ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}"
                            class="required" allowClear="false" canSelectRoot="true" canSelectParent="true" readonly="true" disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('职位')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select multiple="true" path="employee.employeePosts" items="${postList}"
                            itemLabel="postName" itemValue="postCode" class="form-control required" disabled="true"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('公司')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:treeselect id="company" title="${text('公司选择')}"
                            path="employee.company.companyCode" labelPath="employee.company.companyName"
                            url="${ctx}/sys/company/treeData?ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}"
                            btnClass="" class="required" allowClear="true" canSelectRoot="true" canSelectParent="true" readonly="true" disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2" title="">
                            <span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-10">
                            <#form:textarea path="remarks" rows="4" maxlength="500" class="form-control " disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-unit">${text('联系信息')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('电话号码')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <#form:input path="mobile" maxlength="100" class="form-control required mobile" disabled="true"/>
                                <span class="input-group-addon"><i class="fa fa-fw fa-mobile"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('邮箱')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <#form:input path="email" maxlength="300" class="form-control email" disabled="true"/>
                                <span class="input-group-addon"><i class="fa fa-fw fa-envelope"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2" title="">
                            <span class="required hide">*</span> ${text('家庭住址')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="address" maxlength="255" class="form-control address" disabled="true"/>
                        </div>
                    </div>
                </div>
                <!--<div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('办公电话')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <#form:input path="phone" maxlength="100" class="form-control phone"/>
                                <span class="input-group-addon"><i class="fa fa-fw fa-phone"></i></span>
                            </div>
                        </div>
                    </div>
                </div>-->
                <!--<div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('权重(排序)')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="userWeight" maxlength="8" class="form-control digits" placeholder="${text('权重越大排名越靠前，请填写数字。')}"/>
                        </div>
                    </div>
                </div>-->
            </div>
            <div class="form-unit">${text('附件信息')}</div>
            <div class="row">
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2">
                            <span class="required hide">*</span>附件上传：</label>
                        <div class="col-sm-10">
                            <#form:fileupload id="uploadFile" bizKey="${empUser.id}" bizType="empUser_file"
                            uploadType="all" class="" readonly="true" preview="true" disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <% } %>

            <% if(hasPermi('sys:empUser:authRole') && (op == 'add' || op == 'auth')) { %>
            <div class="form-unit">${text('分配角色')}</div>
            <div class="pl10 pb20">
                <table id="roleGrid"></table>
                <#form:hidden name="userRoleString"/>
            </div>
            <% } %>

            <div class="form-unit">${text('系统信息')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="createDate" class="form-control" disabled="true"
                            dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="createBy" class="form-control" disabled="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="updateDate" class="form-control" disabled="true"
                            dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="updateBy" class="form-control" disabled="true"/>
                        </div>
                    </div>
                    <div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-10">
                        <% if (hasPermi('sys:empUser:edit,sys:empUser:authRole', 'or')){ %>
                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
                        <% } %>
                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                    </div>
                </div>
            </div>
        </#form:form>
        </div>
    </div>
<% } %>

<script>
    <% if(hasPermi('sys:empUser:authRole') && (op == 'add' || op == 'auth')) {%>
        // 加载角色列表
        var roleGrid = $("#roleGrid").dataGrid({
            url: '${ctx}/sys/role/treeData',
            postData: [
                {name:'userType',value:'employee'},
                {name:'ctrlPermi',value:'${@Global.getConfig("user.adminCtrlPermi", "2")}'}
            ],
            columnModel: [
                {header:'${text("角色名称")}', name:'name', sortable:false, width:100, align:"center"},
                {header:'${text("角色编码")}', name:'id', sortable:false, width:100, align:"center"}
            ],
            showCheckbox: true,
            autoGridHeight: function(){
                return 'auto';
            },
            autoGridWidth: function(){
                return $('#inputForm .box-body').width()-20;
            },
            ajaxSuccess: function(){
            <% for (role in roleList!){ %>
                    roleGrid.dataGrid('setSelectRow', '${role.roleCode}');
                <% } %>
            }
        });
    <% } %>
    $("#inputForm").validate({
        submitHandler: function(form){
            <% if(hasPermi('sys:empUser:authRole') && (op == 'add' || op == 'auth')) { // 获取选中角色  %>
                $("#userRoleString").val(roleGrid.dataGrid('getSelectRows').join(','));
            <% } %>
            var empNo = $('#employee_empNo').val();
            if (empNo == ''){
                $('#employee_empNo').val($('#loginCode').val());
            }
            js.ajaxSubmitForm($(form), function(data){
                js.showMessage(data.message);
                if(data.result == Global.TRUE){
                    js.closeCurrentTabPage(function(contentWindow){
                        contentWindow.page();
                    });
                }
            }, "json");
        }
    });

    $("#editView").click(function () {
        var id = $("#userCode").val();
        var URL = '${ctx}/sys/empUser/form?userCode=' + id +'&op=edit';
        window.location.href =URL;
    });
</script>


<!--
<script id="treeselectTpl" type="text/template">//&lt;!&ndash;<div>
<#form:treeselect id="{{d.id}}" title="{{d.title}}" name="{{d.name}}" value="{{d.value}}"
	labelName="{{d.labelName}}" labelValue="{{d.labelValue}}" url="{{d.url}}"
	class="{{d.cssClass}}" btnClass="btn-sm" allowClear="true"/>
</div>//&ndash;&gt;</script>
-->
